function addPostController($scope,$state,$http,$stateParams){
    var now = new Date().toLocaleDateString();
    var postId = $stateParams.postId;
    $scope.addFlag = $stateParams.addFlag;
    if($scope.addFlag==false){
        $http({
            url: '/post/getPostById/'+postId,
            method: 'GET',
        }).success(function (response) {
            
                    console.log("response: " + response);
                    $scope.postName = response.postName;
                    $scope.author = response.author;
                    $scope.component = response.component;
                    $scope.date = response.date;
            
            
                }).error(function (response) {
                    alert('error')
                })
    }
    $scope.addPost = function(){
        $http({
            url: '/post/addPost',
            method: 'POST',
            data: {
                postName:$scope.postName,
                author:"张慧兰",
                component:$scope.component,
                date:now
            }
        })
        .success(function (response){
            console.log("response: " + response);
            alert('发布成功');
            $state.go('postBar');
        }).error(function (response) {
            alert('error')
        })
    }
    $scope.updatePost = function(){
        $http({
            url: '/post/updatePost',
            method: 'POST',
            data: {
                postId : postId,
                postName:$scope.postName,
                author:$scope.author,
                component:$scope.component,
                date:$scope.date
            }
        })
        .success(function (response){
            console.log("response: " + response);
            alert('修改成功');
            $state.go('postBar');
        }).error(function (response) {
            alert('error')
        })
    }
    $scope.backToBar = function(){
        $state.go('postBar');
    }
}